<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
      https://leetcode-cn.com/problems/chou-shu-lcof/
      思路：https://leetcode-cn.com/problems/chou-shu-lcof/solution/dong-tai-gui-hua-by-gaoyibo-5/
     */
    function nthUglyNumber(n) {
      if (n === 1) return 1
      let res = [1]
      let a = 0, b = 0, c = 0

      for (let i = 1; i < n; i++) {
        res[i] = Math.min(res[a] * 2, res[b] * 3, res[c] * 5)
        if (res[i] >= res[a] * 2) a++
        if (res[i] >= res[b] * 3) b++
        if (res[i] >= res[c] * 5) c++
      }

      return res[n-1]
    }
  </script>
</body>
</html>